package cn.yl.caner.web;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.yl.caner.domain.LoginData;
import cn.yl.caner.service.LoginService;


public class LoginServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	//登录
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		request.setCharacterEncoding("UTF-8");
		//获取前端来的request
		String account = request.getParameter("account");
		String re_password = request.getParameter("password");
		LoginData logindata = new LoginData();
		logindata.setAccount(account);
		logindata.setPassword(re_password);
		LoginService loginservice =  new LoginService();
		LoginData loginAccount = loginservice.loginAccount(logindata);
		String password	= loginAccount.getPassword();
//		System.out.println(password+123);
		if(re_password.equals(password)) {
			System.out.println("密码正确");
				request.getSession().setAttribute("login_username", account);
				request.getSession().setAttribute("login_password", password);
				response.sendRedirect(request.getContextPath()+"/account.jsp");
			}else {
				System.out.println("密码错误");
				response.sendRedirect(request.getContextPath()+"/index.html");
			}

	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
}
